package com.wceManage.commons;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * api工具类
 * @author Administrator
 *
 */

public class CommonUtil {
	
	private static final Pattern pattern = Pattern.compile("^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9]))\\d{8}$");
	
	/**
	 * 验证手机号
	 * @param phone
	 * @return
	 */
	public static Map<String,Object> validPhone(String phone){
		Map<String,Object> result=new HashMap<String,Object>();
		if(null==phone){
			result.put("msg","手机号不能为空");
			result.put("code",-1);
			return result;
		}
		if(phone.length() != 11){
			result.put("msg","请输入11位手机号");
			result.put("code",-1);
			return result;
		}
		
	    Matcher m = pattern.matcher(phone);
	    boolean isMatch = m.matches();
	    if (!isMatch) {
	        result.put("msg","请填入正确的手机号");
			result.put("code",-1);
			return result;
	    }
	    
	    result.put("msg","验证成功");
		result.put("code",1);
		return result;
	}

	/**
	 * 分页起始数据封装
	 * @param pageNum 页码
	 * @param pageSize 每页显示数量
	 * @return
	 */
	public static int getiDisplayStart(String pageNum,String pageSize){
		if(null==pageNum || null==pageSize){
			return 0;
		}
		int pageNo = Integer.parseInt(pageNum);
		int pageSi= Integer.parseInt(pageSize);
		return (pageNo-1)*pageSi;
	}
}
